<!-- 我要下单 -->
<template>
  <div style="padding: 0 16px;">
    <div style="display: flex;align-items: center;padding-left: 12px 0;">
      <el-tabs v-model="activeName" class="deleteBorder" style="flex: 1;" @tab-click="handleClick">
        <el-tab-pane label="待报价" name="待报价" />
        <el-tab-pane label="已报价" name="已报价" />
        <el-tab-pane label="服务中" name="服务中" />
        <el-tab-pane label="已完成" name="已完成" />
      </el-tabs>

      <el-input placeholder="请输入内容" style="max-width: 220px;margin-right: 16px;" v-model="searchText"/>
      <el-button type="primary" icon="el-icon-search" @click="onSearch">搜索</el-button>
    </div>
    <order_house_table :dataSource="dataSource" 
      @viewDetailHandle="viewDetailHandle"
      @takePriceHandle="takePriceHandle"
      />
  </div>
</template>

<script>
import OrderHouseAPI from "./api"
import order_house_table from './table.vue'
import TakePrice from './takeprice.vue'
export default {
  components: {
    order_house_table,
    TakePrice,
  },
  data() {
    return {
      activeName: '待报价',
      name: '待报价',
      dataSource:[],
      searchText: ''
    }
  },
  mounted(){
    this.handleClick();
  },  
  methods:{
    handleClick() {
      if(this.activeName == '待报价') {
        this.netFetchListWait()
      } else {
        this.netFetchListOther();
      }
    },

    async netFetchListWait(){
      let res = await OrderHouseAPI.netYzOrderGetList({ searchText: this.searchText })
      let {status,msg,data} = res.data;
      if(status == 200) {
        this.dataSource = data;
      } else {
        this.$message({
          message: msg,
          type: 'error',
          showClose: true,
          duration: 3000,
        });
        
      }
    },

    async netFetchListOther(){
      let userInfo = sessionStorage.getItem("userInfo");
      let res = await OrderHouseAPI.netYzOrderTakeList({
        status:this.activeName,
        orderUserId:userInfo.id,
        searchText: this.searchText
      })
      let {status,msg,data} = res.data;
      if(status == 200) {
        this.dataSource = data;
      } else {
        this.$message({
          message: msg,
          type: 'error',
          showClose: true,
          duration: 3000,
        });
        
      }
    },

  
    viewDetailHandle(id) {
      this.$router.push({name:"order_house_detail",params:{id}})
    },
    
    takePriceHandle(data) {
      this.$router.push({name:"order_house_takeprice",params:data})
    },
    onSearch() {
      this.handleClick();
    }
  }
}
</script>

<style>
.deleteBorder .el-tabs__nav-wrap::after{
    height: 0;
  }
</style>
